# 整数数组索引
# import numpy as np
#
# x = np.array([[1, 2], [3, 4], [5, 6]])
# y = x[[0, 1, 2], [0, 1, 0]]
# print(y)

# import numpy as np
#
# x = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]])
# print('我们的数组是：')
# print(x)
# print()
# # rows = np.array([[0, 0], [3, 3]])
# # cols = np.array([[0, 2], [0, 2]])
# rows = [0, 0, 3, 3]
# cols = [0, 2, 0, 2]
# y = x[rows, cols]
# print('这个数组的四个角元素是：')
# print(y)

# import numpy as np
#
# a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# b = a[1:3, 1:3]
# c = a[1:3, [1, 2]]
# d = a[..., 1:]
# print(b)
# print(c)
# print(d)

# bool索引

# import numpy as np
#
# x = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]])
# print('我们的数组是：')
# print(x)
# print()
# # 现在我们会打印出大于 5 的元素
# print('大于 5 的元素是：')
# print(x[x > 5])

# import numpy as np
# a = np.array([np.nan, 1, np.nan, 5, 6])
# print(a[~np.isnan(a)])

# 花式索引
# import numpy as np
#
# x = np.arange(9)
# print(x)
# # 一维数组读取指定下标对应的元素
# print("-------读取下标对应的元素-------")
# x2 = x[[0, 6]] # 使用花式索引
# print(x2)
#
# print(x2[0])
# print(x2[1])


import numpy as np

x=np.arange(32).reshape((8,4))
print(x)
# 二维数组读取指定下标对应的行
print("-------读取下标对应的行-------")
print (x[[4,2,1,7]])

# # 如果需要将多个元素组合成新数组
# x2 = np.array([x[0], x[6]])  # 创建包含这两个元素的新数组
# print(x2)                    # 输出: [0 6]
#
# # 或者使用 concatenate
# x2 = np.concatenate([[x[0]], [x[6]]])
# print(x2)                    # 输出: [0 6]